package com.twohand.admin.Util;

import com.qcloud.cos.COSClient;
import com.qcloud.cos.ClientConfig;
import com.qcloud.cos.auth.BasicCOSCredentials;
import com.qcloud.cos.auth.COSCredentials;
import com.qcloud.cos.http.HttpProtocol;
import com.qcloud.cos.region.Region;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;


@Component
public class CosUtil {
    @Getter
    @Setter
    private static String SecretId;
    @Getter
    @Setter
    private static String SecretKey;
    @Getter
    @Setter
    private static String bucket;
    @Getter
    @Setter
    private static String bucketOrigin;
    @Getter
    @Setter
    private static Integer cosDuration;
    @Getter
    @Setter
    private static COSClient cosClient;

    @Bean
    public int init(){
        COSCredentials cred = new BasicCOSCredentials(getSecretId(),getSecretKey());
        Region region = new Region(getBucketOrigin());
        ClientConfig clientConfig = new ClientConfig(region);
        clientConfig.setHttpProtocol(HttpProtocol.http);
        setCosClient(new COSClient(cred,clientConfig));
        // System.out.println("初始化完毕");
        return 0;
    }

}
